package com.ruoyi.web.controller.sms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SmsPrizeHistory;
import com.ruoyi.system.service.ISmsPrizeHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖品兑换记录Controller
 *
 * @author DRIES
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/sms/history")
public class SmsPrizeHistoryController extends BaseController
{
    @Autowired
    private ISmsPrizeHistoryService smsPrizeHistoryService;

    /**
     * 查询奖品兑换记录列表
     */
    @PreAuthorize("@ss.hasPermi('sms:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsPrizeHistory smsPrizeHistory)
    {
        startPage();
        List<SmsPrizeHistory> list = smsPrizeHistoryService.selectSmsPrizeHistoryList(smsPrizeHistory);
        return getDataTable(list);
    }

    /**
     * 导出奖品兑换记录列表
     */
    @PreAuthorize("@ss.hasPermi('sms:history:export')")
    @Log(title = "奖品兑换记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsPrizeHistory smsPrizeHistory)
    {
        List<SmsPrizeHistory> list = smsPrizeHistoryService.selectSmsPrizeHistoryList(smsPrizeHistory);
        ExcelUtil<SmsPrizeHistory> util = new ExcelUtil<SmsPrizeHistory>(SmsPrizeHistory.class);
        util.exportExcel(response, list, "奖品兑换记录数据");
    }

    /**
     * 获取奖品兑换记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsPrizeHistoryService.selectSmsPrizeHistoryById(id));
    }

    /**
     * 新增奖品兑换记录
     */
    @PreAuthorize("@ss.hasPermi('sms:history:add')")
    @Log(title = "奖品兑换记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsPrizeHistory smsPrizeHistory)
    {
        return toAjax(smsPrizeHistoryService.insertSmsPrizeHistory(smsPrizeHistory));
    }

    /**
     * 修改奖品兑换记录
     */
    @PreAuthorize("@ss.hasPermi('sms:history:edit')")
    @Log(title = "奖品兑换记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsPrizeHistory smsPrizeHistory)
    {
        return toAjax(smsPrizeHistoryService.updateSmsPrizeHistory(smsPrizeHistory));
    }

    /**
     * 删除奖品兑换记录
     */
    @PreAuthorize("@ss.hasPermi('sms:history:remove')")
    @Log(title = "奖品兑换记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsPrizeHistoryService.deleteSmsPrizeHistoryByIds(ids));
    }
}
